﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WordReverse
{
    class Program
    {
        static void strSplit(string str, string splitSymbol)
        {
            int prevIndex = 0, index = 0;
            int counter = 0, charcounter = 0;
            string strTemp;

            foreach (char ch1 in str)
            {
                if (ch1 == Convert.ToChar(splitSymbol))
                {
                    charcounter++;
                }
            }

            string[] sb = new string[charcounter+1];

            do
            {
                index = str.IndexOf(splitSymbol, prevIndex);
                if (index == -1)
                {
                    index = str.Length;
                }
                string s = str.Substring(prevIndex, index - prevIndex);
                prevIndex = index + 1;
                sb[counter] = s;
                counter++;
            }
            while (str.IndexOf(splitSymbol, index) != -1);

            for (int i = 0, j = sb.Length - 1; i < j; i++, j--)
            {
                strTemp = sb[i];
                sb[i] = sb[j];
                sb[j] = strTemp;
            }
            Console.WriteLine("[{0}]", string.Join(", ", sb));
        }

        static void Main(string[] args)
        {
            string str = "Kostya,Irina,Yan,Roman,Alex,Alexey,Elena,Timur";
            strSplit(str, ",");
        }
    }
}
